//
//  FirstHomeCell.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/5.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "FirstHomeCell.h"

@interface FirstHomeCell()<SDCycleScrollViewDelegate>

@property(nonatomic,strong)SDCycleScrollView *cycleScrollView;

@end

@implementation FirstHomeCell


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        UIView *leftView = [[UIView alloc] init];
        [self.contentView addSubview:leftView];
        
        CGFloat leftW = WIDTH/3+20;
        CGFloat rightW = WIDTH-leftW;
       
        NSLog(@"%@",self.cycleArr);
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0,0,leftW-1,HEIGHT/4) delegate:nil placeholderImage:[UIImage imageNamed:@"leftBgImg.jpg"]];
        _cycleScrollView.delegate = self;
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _cycleScrollView.pageDotColor = [UIColor whiteColor];
        _cycleScrollView.currentPageDotColor = DEFAULT_COLOR;
        [leftView addSubview:_cycleScrollView];
        

        //黑线
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(leftW,0,2,HEIGHT/4)];
        lineView.backgroundColor = BACKGROUND_COLOR;
        [self.contentView addSubview:lineView];
        
        
        self.ad2Img =  [[UIImageView alloc] init];
        [self.contentView addSubview:_ad2Img];
        
        self.ad2btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:_ad2btn];
        
        //黑线
        UIView *lineView1= [[UIView alloc] initWithFrame:CGRectMake(leftW,HEIGHT/8,leftW*2,2)];
        lineView1.backgroundColor = BACKGROUND_COLOR;
        [self.contentView addSubview:lineView1];
        
        self.ad3Img =  [[UIImageView alloc] init];
        [self.contentView addSubview:_ad3Img];
        self.ad3btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:_ad3btn];
        
        
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.leading.equalTo(self.mas_leading);
            make.top.equalTo(self.mas_top);
            make.bottom.equalTo(self.mas_bottom);
            make.width.mas_equalTo(leftW-1);
        }];
        
        [_ad2Img mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.trailing.equalTo(self.mas_trailing);
            make.top.equalTo(self.mas_top);
            make.height.mas_equalTo(HEIGHT/8-1);
            make.width.mas_equalTo(rightW-1);
        }];
        
        [_ad2btn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.trailing.equalTo(self.mas_trailing);
            make.top.equalTo(self.mas_top);
            make.height.mas_equalTo(HEIGHT/8-1);
            make.width.mas_equalTo(rightW-1);
        }];
        
        
        [_ad3Img mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.trailing.equalTo(self.mas_trailing);
            make.top.equalTo(lineView1.mas_bottom);
            make.height.mas_equalTo(HEIGHT/8-2);
            make.width.mas_equalTo(rightW-1);
        }];
        
        
        [_ad3btn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.trailing.equalTo(self.mas_trailing);
            make.top.equalTo(lineView1.mas_bottom);
            make.height.mas_equalTo(HEIGHT/8-2);
            make.width.mas_equalTo(rightW-1);
        }];
        
    }
    return self;
}


- (void)setCycleArr:(NSArray *)cycleArr
{
//    NSLog(@"%@",cycleArr);
    _cycleArr = cycleArr;
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *tempDict in cycleArr) {
        NSString *str = [NSString stringWithFormat:@"%@",tempDict[@"img"]];
        [arr addObject:str];
    }
    _cycleScrollView.imageURLStringsGroup = arr;
}


/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if ([self.delegate respondsToSelector:@selector(homeFirstHomeCellAd1Index:)]) {
        [self.delegate homeFirstHomeCellAd1Index:index];
    }
}

@end
